<template>
    <div class="goodsrent">
        <el-table :data="rentReq.rentReqList" style="width: 100%" @selection-change="selhandle">
            <el-table-column prop="Userid" label="学号" width="150" />
            <el-table-column prop="Name" label="货物名称" />
            <el-table-column prop="Name" label="数量">
                <template #default="scope">
                    <span>1</span>
                </template>
            </el-table-column>
            <el-table-column prop="Create_time" label="起始时间" />
            <el-table-column prop="Currten_time" label="截止时间" />
            <el-table-column prop="Currinvent" label="库存" width="150" />
            <el-table-column prop="Orderid" label="是否同意租借?">
                <template #default="scope">
                    <el-button type="success" @click="isAgree(1, scope.row.Orderid)">是</el-button>
                    <el-button type="danger" @click="isAgree(0, scope.row.Orderid)">否</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
import axios from 'axios';
import { ref, reactive, toRefs } from 'vue';
import { useRoute, useRouter } from "vue-router";
import { goodsRentApi, AgreeApi } from "../request/api";
import { rentReqStore } from "../store/rentReq";
// Create_time: "2023-03-20T16:20:09+08:00"
// Currinvent: 97
// Currten_time: "2023-03-27T15:23:04+08:00"
// Id: 1
// Isacceptornot: "1"
// Name: "罗生门"
// Orderid: 0
// Userid: 1
const Router = useRouter();
const Route = useRoute();
const rentReq = reactive(rentReqStore());
goodsRentApi().then(res => {
    rentReq.addrentReqList(res);
    console.log(res);
})


// 选中操作
const selhandle = (val) => {
    console.log(val);
}
// 同意租借
const agreeRent = (val) => {
    console.log(val);
}
const isAgree = (val, id) => {
    console.log(val, id);
    AgreeApi({
        isAgree: String(val),
        rentReqId: String(id)
    }).then(res => {
        console.log(res);
        if (res == "") {
            ElMessage({
                message: "已处理过的请求",
                type: 'success'
            });
        }
        if (res.askData.title && res.askData.title == "未同意") {
            ElMessage({
                message: "未同意",
                type: 'error'
            });
        }
        if (res.agreeData.title && res.agreeData.title == 1) {
            ElMessage({
                message: "已同意",
                type: 'success'
            });
        }
    })
}

</script>
 
<style lang = "less" scoped>
:deep(.el-table .cell) {
    text-align: center;
}

// is-leaf
:deep(.el-table .is-leaf .cell) {
    color: #000;
    font-weight: 700;
}
</style>